package com.pk.platform.business.flow.web;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.hibernate.Hibernate;

import com.pk.platform.business.core.web.GenericAction;
import com.pk.platform.business.data.service.IBaseDataService;
import com.pk.platform.business.flow.service.IFlowDefineService;
import com.pk.platform.business.flow.vo.FlowModuleVO;
import com.pk.platform.business.flow.vo.WorkFlowVO;
import com.pk.platform.domain.data.BaseData;
import com.pk.platform.domain.flow.FlowModule;
import com.pk.platform.domain.flow.WorkFlow;
import com.pk.platform.util.StringConverter;
import com.pk.platform.util.constant.Constant;

public class FlowDefineAction extends GenericAction {

	private List<FlowModule> fmList = new ArrayList<FlowModule>();
	
	private IFlowDefineService flowDefineService;
	
	private FlowModuleVO fmvo = new FlowModuleVO();
	
	private FlowModule fm = new FlowModule();
	
	private String[] fmIds;
	
	private IBaseDataService baseDataService;
	
	private List<BaseData> bdList = new ArrayList<BaseData>();
	
	private String actors;

	private String nodeType;

	private String flowType;
	
	private WorkFlow wf = new WorkFlow();

	private WorkFlowVO wfvo = new WorkFlowVO();
	
	public String flowManage()
	{
		return SUCCESS;
	}
	
	public String moduleList()
	{
		fmList = flowDefineService.queryFlowModule();
		return SUCCESS;
	}
	
	public String flowList()
	{
		lp = flowDefineService.queryWorkFlow(wfvo, pager);
		return SUCCESS;
	}
	
	public String saveModule()
	{
		flowDefineService.saveFlowModule(fm);
		return SUCCESS;
	}
	
	public String toAddModule()
	{
		return SUCCESS;
	}
	
	public String toUpdateModule()
	{
		fm = flowDefineService.queryFlowModuleById(fm.getId());
		return SUCCESS;
	}
	
	public String delModule()
	{
		if(fmIds != null)
		{
			message = flowDefineService.delFlowModule(fmIds);
		}
		return SUCCESS;
	}
	
	public String toAddFlow()
	{
		flowType = "add";
		bdList = baseDataService.queryBaseDataByParentId(Constant.FLOW_STATUS);
		return SUCCESS;
	}
	
	public String actorsSelect()
	{
		list = flowDefineService.queryActorsList();
		return SUCCESS;
	}
	
	public String toUpdateFlow()
	{
		flowType = "update";
		bdList = baseDataService.queryBaseDataByParentId(Constant.FLOW_STATUS);
		wf = flowDefineService.queryFlowById(wf.getId());
		wf.setContentStr(StringConverter.blobToString(wf.getContent()));
		return SUCCESS;
	}
	
	public String addFlow() throws Exception
	{
		flowDefineService.addFlow(wf);
		return SUCCESS;
	}

	public String updateFlow() throws Exception
	{
		flowDefineService.updateFlow(wf);
		return SUCCESS;
	}
	
	public String delFlow()
	{
		flowDefineService.delFlow(wf.getId());
		return SUCCESS;
	}
	
	
	

	public List<FlowModule> getFmList() {
		return fmList;
	}

	public void setFmList(List<FlowModule> fmList) {
		this.fmList = fmList;
	}

	public IFlowDefineService getFlowDefineService() {
		return flowDefineService;
	}

	public void setFlowDefineService(IFlowDefineService flowDefineService) {
		this.flowDefineService = flowDefineService;
	}

	public FlowModuleVO getFmvo() {
		return fmvo;
	}

	public void setFmvo(FlowModuleVO fmvo) {
		this.fmvo = fmvo;
	}

	public FlowModule getFm() {
		return fm;
	}

	public void setFm(FlowModule fm) {
		this.fm = fm;
	}

	public String[] getFmIds() {
		return fmIds;
	}

	public void setFmIds(String[] fmIds) {
		this.fmIds = fmIds;
	}

	public IBaseDataService getBaseDataService() {
		return baseDataService;
	}

	public void setBaseDataService(IBaseDataService baseDataService) {
		this.baseDataService = baseDataService;
	}

	public List<BaseData> getBdList() {
		return bdList;
	}

	public void setBdList(List<BaseData> bdList) {
		this.bdList = bdList;
	}

	public String getActors() {
		return actors;
	}

	public void setActors(String actors) {
		this.actors = actors;
	}

	public String getNodeType() {
		return nodeType;
	}

	public void setNodeType(String nodeType) {
		this.nodeType = nodeType;
	}

	public String getFlowType() {
		return flowType;
	}

	public void setFlowType(String flowType) {
		this.flowType = flowType;
	}

	public WorkFlow getWf() {
		return wf;
	}

	public void setWf(WorkFlow wf) {
		this.wf = wf;
	}

	public WorkFlowVO getWfvo() {
		return wfvo;
	}

	public void setWfvo(WorkFlowVO wfvo) {
		this.wfvo = wfvo;
	}
	
}
